
// 普通攻击技能
class BasicAttack extends Skill {
    constructor() {
        super(
            'basic_attack',
            '普通攻击',
            '对目标造成100%攻击力的伤害',
            SkillType.ATTACK,
            0
        );
    }

    calculate(source, target) {
        const damage = source.attack;
        target.hp -= damage;
        return {
            success: true,
            message: `${source.name}对${target.name}造成了${damage}点伤害`,
            damage: damage
        };
    }
}

// 吸血技能
class LifeSteal extends Skill {
    constructor() {
        super(
            'life_steal',
            '生命汲取',
            '对目标造成80%攻击力的伤害，并回复伤害量50%的生命值',
            SkillType.ATTACK,
            3
        );
    }

    calculate(source, target) {
        const damage = Math.floor(source.attack * 0.8);
        const heal = Math.floor(damage * 0.5);
        
        target.hp -= damage;
        source.hp += heal;
        
        return {
            success: true,
            message: `${source.name}对${target.name}造成了${damage}点伤害，并回复了${heal}点生命值`,
            damage: damage,
            heal: heal
        };
    }
}

// 治疗技能
class Heal extends Skill {
    constructor() {
        super(
            'heal',
            '治疗术',
            '恢复目标30%最大生命值的生命值',
            SkillType.HEAL,
            4
        );
    }

    calculate(source, target) {
        const healAmount = Math.floor(target.maxHp * 0.3);
        const actualHeal = Math.min(healAmount, target.maxHp - target.hp);
        target.hp += actualHeal;
        
        return {
            success: true,
            message: `${source.name}为${target.name}恢复了${actualHeal}点生命值`,
            heal: actualHeal
        };
    }
}

// 防御技能
class Defense extends Skill {
    constructor() {
        super(
            'defense',
            '防御姿态',
            '提高50%防御力，持续2回合',
            SkillType.DEFENSE,
            5
        );
    }

    calculate(source) {
        const defenseBonus = Math.floor(source.defense * 0.5);
        source.addBuff('defense_boost', {
            duration: 2,
            value: defenseBonus,
            type: 'defense'
        });
        
        return {
            success: true,
            message: `${source.name}进入防御姿态，防御力提升${defenseBonus}点`,
            defenseBonus: defenseBonus
        };
    }
}

// 重击技能
class HeavyStrike extends Skill {
    constructor() {
        super(
            'heavy_strike',
            '重击',
            '对目标造成150%攻击力的伤害，但有25%几率击空',
            SkillType.ATTACK,
            2
        );
    }

    calculate(source, target) {
        // 25%几率击空
        if (Math.random() < 0.25) {
            return {
                success: false,
                message: `${source.name}的重击未命中${target.name}`
            };
        }

        const damage = Math.floor(source.attack * 1.5);
        target.hp -= damage;
        
        return {
            success: true,
            message: `${source.name}的重击对${target.name}造成了${damage}点伤害`,
            damage: damage
        };
    }
}

const SkillMapper = {
    'basic_attack': BasicAttack,
    'life_steal': LifeSteal,
    'heal': Heal,
    'defense': Defense,
    'heavy_strike': HeavyStrike
};

